home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98c.txt / 000029_icon-group-sender _Tue Sep 15 12:29:41 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) with SMTP id MAA10444
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Tue, 15 Sep 1998 12:29:39 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA03607; Tue, 15 Sep 1998 12:29:11 -0700
  7. Message-Id: <35FEA142.5CE0@gte.net>
  8. Date: Tue, 15 Sep 1998 12:17:54 -0500
  9. From: MJE <evans@gte.net>
  10. Reply-To: evans@gte.net
  11. Organization: None
  12. X-Mailer: Mozilla 3.01 (Win95; I)
  13. Mime-Version: 1.0
  14. To: icon-group@optima.CS.Arizona.EDU
  15. Subject: Re: Context Switching
  16. References: <9809142152.memo.74091@BIX.com>
  17. Content-Type: text/plain; charset=us-ascii
  18. Content-Transfer-Encoding: 7bit
  19. Content-Transfer-Encoding: 7bit
  20. Content-Transfer-Encoding: 7bit
  21. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  22. Content-Transfer-Encoding: 7bit
  23. Status: RO
  24.  
  25. Thanks, but I think you missed my point.  The hidden assumption here is
  26. that Icon function calls shall behave exactly like C function calls.  I
  27. am trying to say that, with auxiliary data structures, the job might be
  28. done without threads.
  29.  
  30. The Icon compiler could be made smart enough to know when a function
  31. involves co-expressions, and when it does, not to use "standard" stack
  32. frames that have to be swapped in and out, but some other kind of data
  33. structure (heap allocation) for the local variables.
  34.  
  35. I understand that if you need to replace processor-level stack frames,
  36. then yes you need assembler code.  I have done that myself in
  37. asynchronous drivers that return from deeply nested routines.
  38.  
  39. My point is:  maybe there's a better way to handle the context switching
  40. requirement than stack-swapping.  There is no law that says Icon has to
  41. declare local variables internally in the same fashion as C, on the
  42. stack frame.
  43.  
  44. Mark
  45.  
  46.  
  47.  
  48.  
  49. cwills@bix.com wrote:
  50. > Yes.. it really does require a seperate "thread" of execution.  The
  51. > coswitch routine (the assembler code used for doing the context switch)
  52. > replaces the C stack frame with a different stack frame then re-invokes
  53. > the interepreter code.  Note that this is not a "whole seperate executable"
  54. > but preserving the current dynamic set of variables while the co-routine
  55. > is running.
  56. > Also note that if you dig deep enough into co-processes (co-routines and
  57. > co-expressions) you will find that this is what is really going on under
  58. > the covers.
  59. > The algorithm used by Icon expressed in a C-ish pseudeo code is:
  60. > coswitch( old_cs, new_cs, first )
  61. > int *old_cs, *new_cs, first;
  62. > {
  63. >     /* save SP, frame pointers, and other registers in old_cs */
  64. >     if ( first == 0 )
  65. >     {
  66. >         /* load sp from new_sp[0] and clear frame pointers */
  67. >         interp( 0, 0 );
  68. >         syserr( "interp() returned in coswitch" );
  69. >     }
  70. >     else
  71. >     {
  72. >         /* load sp, frame pointers and other registers from new_cs */
  73. >     }
  74. > }
  75. > ---------
  76. > To implement the coswitch function using threads, one would have
  77. > to locate where coswitch is called, change the allocation of the
  78. > co-expression stack to a creation of a thread that immediately blocks
  79. > on a semaphore defined in the co-expression block.
  80. > Coswitch then would be passed the current co-expression's semaphore
  81. > and the co-expression's semaphore to swap to, "post" the called semaphore
  82. > and wait on the calling semaphore (if any of that makes sense).
  83. > Taking this alittle further, one might want to have a "master" thread
  84. > (the original thread created by the system) and then when &main is created
  85. > create a new thread for &main.  This would allow &main to be "destroyed"
  86. > and still have the "master" thread always there.  The master thread could
  87. > be used as a syncronizer if for some reason the OS needed stuff created
  88. > by a parent thread.  If done correctly, co-expressions could actually
  89. > be executed in parallel (have the master thread perform all memory
  90. > allocations, GC, file, etc).
  91. > Cheyenne
  92.  
  93.